//
// Created by vcq on 21/2/9.
//
#pragma once

#include "dbng.hpp"

struct require {
    int id;
    string name;
    string note;
    int _plan_id;//培养计划编号
    int _finish_id;//毕业要求
};
REFLECTION(require, id, name, _plan_id, _finish_id,note)

json mgetRequire(basic_string_view<char> id,basic_string_view<char> _plan_id,basic_string_view<char> _finish_id) {
    string sql = "select * from `require` where 1=1 ";
    if (!id.empty()) {
        sql += " and id =";
        sql += id;
    }
    if (!_plan_id.empty()) {
        sql += " and _plan_id =";
        sql += _plan_id;
    }
    if (!_finish_id.empty()) {
        sql += " and _finish_id =";
        sql += _finish_id;
    }
    Dao dao;
    nlohmann::json article_list,ret,item;
    auto v = dao.query<require>(sql);
    for (auto &o : v) {
        item["id"] = o.id;
        item["name"] = o.name;
        item["note"] = o.note;
        item["_plan_id"] = o._plan_id;
        item["_finish_id"] = o._finish_id;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}
void MAddRequire(const struct require& require1){
    Dao dao;
    dao.update_object(require1);
}
void MDeleteRequire(basic_string_view<char> id){
    MDeleteAll("require",id);
}